
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>Chapter&nbsp;10.&nbsp;Utility Functions - APOC User Guide 3.4</title>
      <link rel="stylesheet" type="text/css" href="../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../javascript/datatable.js" type="text/javascript"></script><script src="../javascript/colorize.js" type="text/javascript"></script><script src="../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../javascript/mp-nav.js" type="text/javascript"></script><script src="../javascript/versionswitcher.js" type="text/javascript"></script><script src="../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../database-integration/load-ldap/" title="8.7.&nbsp;Load LDAP"></link>
      <link rel="next" href="conversion-functions/" title="10.1.&nbsp;Conversion Functions"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../database-integration/load-ldap/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Load LDAP</a></span><span class="nav-current">
               <p class="nav-title hidden">Chapter&nbsp;10.&nbsp;Utility Functions</p></span><span class="nav-next"><a accesskey="n" href="conversion-functions/">Conversion Functions<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="chapter" id="utilities">
         <div class="titlepage">
            <div>
               <div>
                  <h1 class="title">Chapter&nbsp;10.&nbsp;Utility Functions</h1>
               </div>
            </div>
         </div>
         <p>Cypher brings along some basic functions for math, text, collections and maps.</p>
         <div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><a class="xref" href="conversion-functions/" title="10.1.&nbsp;Conversion Functions">Section&nbsp;10.1, &#8220;Conversion Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="map-functions/" title="10.2.&nbsp;Map Functions">Section&nbsp;10.2, &#8220;Map Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="collection-list-functions/" title="10.3.&nbsp;Collection Functions">Section&nbsp;10.3, &#8220;Collection Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="text-functions/" title="10.4.&nbsp;Text Functions">Section&nbsp;10.4, &#8220;Text Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="math-functions/" title="10.5.&nbsp;Math Functions">Section&nbsp;10.5, &#8220;Math Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="data-extraction-functions/" title="10.10.&nbsp;Extract Domain">Section&nbsp;10.10, &#8220;Extract Domain&#8221;</a></li>
               <li class="listitem"><a class="xref" href="datetime-conversions/" title="10.11.&nbsp;Date and Time Conversions">Section&nbsp;10.11, &#8220;Date and Time Conversions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="temporal-conversions/" title="10.12.&nbsp;Temporal Functions">Section&nbsp;10.12, &#8220;Temporal Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="number-conversions/" title="10.13.&nbsp;Number Format Conversions">Section&nbsp;10.13, &#8220;Number Format Conversions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="exact-math-functions/" title="10.14.&nbsp;Exact Math">Section&nbsp;10.14, &#8220;Exact Math&#8221;</a></li>
               <li class="listitem"><a class="xref" href="phonetic-functions/" title="10.9.&nbsp;Phonetic Text Functions">Section&nbsp;10.9, &#8220;Phonetic Text Functions&#8221;</a></li>
               <li class="listitem"><a class="xref" href="node-difference/" title="10.15.1.&nbsp;Diff">Section&nbsp;10.15.1, &#8220;Diff&#8221;</a></li>
               <li class="listitem"><a class="xref" href="spatial/" title="10.6.&nbsp;Spatial">Section&nbsp;10.6, &#8220;Spatial&#8221;</a></li>
               <li class="listitem"><a class="xref" href="static-values/" title="10.7.&nbsp;Static Value Storage">Section&nbsp;10.7, &#8220;Static Value Storage&#8221;</a></li>
               <li class="listitem"><a class="xref" href="utility-functions/" title="10.8.&nbsp;Utilities">Section&nbsp;10.8, &#8220;Utilities&#8221;</a></li>
               <li class="listitem"><a class="xref" href="bitwise-operations/" title="10.16.&nbsp;Bitwise operations">Section&nbsp;10.16, &#8220;Bitwise operations&#8221;</a></li>
               <li class="listitem"><a class="xref" href="atomic-updates/" title="10.17.&nbsp;Atomic">Section&nbsp;10.17, &#8220;Atomic&#8221;</a></li>
               <li class="listitem"><a class="xref" href="#log" title="10.19.1.&nbsp;Log Procedures">Section&nbsp;10.19.1, &#8220;Log Procedures&#8221;</a></li>
            </ul>
         </div>
         <section class="section" id="_atomic_examples">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a class="anchor" href="#_atomic_examples"></a>10.18.&nbsp;Atomic Examples
                     </h2>
                  </div>
               </div>
            </div>
            <p><span class="formalpara-title">add.&nbsp;</span>Dataset
            </p><pre class="programlisting highlight"><code data-lang="cypher">CREATE (p:Person {name:'Tom',age: 40})</code></pre><p>We can add 10 to the property <code class="literal">age</code></p><pre class="programlisting highlight"><code data-lang="cypher">MATCH (n:Person {name:'Tom'})
CALL apoc.atomic.add(n,'age',10,5) YIELD oldValue, newValue
RETURN n</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.add.png" width="800" alt="apoc.atomic.add"></img></div>
            </div>
            <p><span class="formalpara-title">subtract.&nbsp;</span>From the previous example we can go back to <code class="literal">age</code>: 40
            </p><pre class="programlisting highlight"><code data-lang="cypher">MATCH (n:Person {name:'Tom'})
CALL apoc.atomic.subtract(n,'age',10,5) YIELD oldValue, newValue
RETURN n</code></pre><p><span class="formalpara-title">concat.&nbsp;</span>Dataset
            </p><pre class="programlisting highlight"><code data-lang="cypher">CREATE (p:Person {name:'Will',age: 35})</code></pre><pre class="programlisting highlight"><code data-lang="cypher">MATCH (p:Person {name:'Will',age: 35})
CALL apoc.atomic.concat(p,"name",'iam',5) YIELD newValue
RETURN p</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.concat.png" width="800" alt="apoc.atomic.concat"></img></div>
            </div>
            <p><span class="formalpara-title">insert.&nbsp;</span>Dataset
            </p>
            <p>we add a propery <code class="literal">children</code> that is an array
            </p><pre class="programlisting highlight"><code data-lang="cypher">CREATE (p:Person {name:'Tom', children: ['Anne','Sam','Paul']})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.insert.png" width="800" alt="apoc.atomic.insert"></img></div>
            </div>
            <p>Now we add <code class="literal">Mary</code> to propery children at the position 2
            </p><pre class="programlisting highlight"><code data-lang="cypher">MATCH (p:Person {name:'Tom'})
CALL apoc.atomic.insert(p,'children',2,'Mary',5) YIELD newValue
RETURN p</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.insert.result.png" width="800" alt="apoc.atomic.insert.result"></img></div>
            </div>
            <p><span class="formalpara-title">remove.&nbsp;</span>Dataset
            </p><pre class="programlisting highlight"><code data-lang="cypher">CREATE (p:Person {name:'Tom', cars: ['Class A','X3','Focus']})</code></pre><p>Now we remove the element <code class="literal">X3</code> which is at the position 1 from the array <code class="literal">cars</code></p><pre class="programlisting highlight"><code data-lang="cypher">MATCH (p:Person {name:'Tom'})
CALL apoc.atomic.remove(p,'cars',1,5) YIELD newValue
RETURN p</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.remove.png" width="800" alt="apoc.atomic.remove"></img></div>
            </div>
            <p><span class="formalpara-title">update.&nbsp;</span>Dataset
            </p><pre class="screen highlight"><code>CREATE (p:Person {name:'Tom', salary1:1800, salary2:1500})</code></pre><p>We want to update <code class="literal">salary1</code> with the result of an expression.
               The expression always have to be referenced with the <code class="literal">n.</code> that refers to the node/rel passed as parameter.
               If we rename our node/rel (as in the example above) we have anyway to refer to it in the expression as <code class="literal">n</code>.
            </p><pre class="programlisting highlight"><code data-lang="cypher">MATCH (p:Person {name:'Tom'})
CALL apoc.atomic.update(p,'salary1','n.salary1*3 + n.salary2',5) YIELD newValue
RETURN p</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.atomic.update.png" width="800" alt="apoc.atomic.update"></img></div>
            </div>
         </section>
         <section class="section" id="_log">
            <div class="titlepage">
               <div>
                  <div>
                     <h2 class="title" style="clear: both"><a class="anchor" href="#_log"></a>10.19.&nbsp;Log
                     </h2>
                  </div>
               </div>
            </div>
            <section class="section" id="log">
               <div class="titlepage">
                  <div>
                     <div>
                        <h3 class="title"><a class="anchor" href="#log"></a>10.19.1.&nbsp;Log Procedures
                        </h3>
                     </div>
                  </div>
               </div>
               <p>APOC provide a set of store procedures in order to add log functionality:</p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" style="list-style-type: disc; ">
                     <li class="listitem"><code class="literal">apoc.log.info</code>: logs info message
                     </li>
                     <li class="listitem"><code class="literal">apoc.log.error</code>: logs error message
                     </li>
                     <li class="listitem"><code class="literal">apoc.log.warn</code>: logs warn message
                     </li>
                     <li class="listitem"><code class="literal">apoc.log.debug</code>: logs debug message
                     </li>
                  </ul>
               </div>
               <p>Every log procedure has the following signature:</p>
               <p><code class="literal">apoc.log.&lt;name&gt;(message, params)</code></p>
               <p>Available configuration:</p>
               <div class="informaltable">
                  <div class="table" id="d0e13704">
                     <table class="informaltable" border="1">
                        <colgroup>
                           <col class="col_1"></col>
                           <col class="col_2"></col>
                           <col class="col_3"></col>
                        </colgroup>
                        <thead>
                           <tr>
                              <th style="text-align: left; vertical-align: top; ">property</th>
                              <th style="text-align: left; vertical-align: top; ">type</th>
                              <th style="text-align: left; vertical-align: top; ">description</th>
                           </tr>
                        </thead>
                        <tbody>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal"><code class="literal">apoc.user.log.type</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">enum[none, safe, raw] (default value <code class="literal">safe</code>)</code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>type of logging:</p>
                                 
                                 <div class="itemizedlist">
                                    <ul style="list-style-type: disc; " class="itemizedlist">
                                       <li class="listitem"><code class="literal">node</code>: disable the procedures
                                       </li>
                                       <li class="listitem"><code class="literal">safe</code>: replace all <code class="literal">.</code> and whitespace (space and tab) with underscore and lowercase all characters
                                       </li>
                                       <li class="listitem"><code class="literal">raw</code>: left the messages as-is
                                       </li>
                                    </ul>
                                 </div>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal"><code class="literal">apoc.user.log.window.ops</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">int (default value <code class="literal">10</code>)</code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>num of logs permitted in a time-window, exceeded this quota every log message will be skip</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal"><code class="literal">apoc.user.log.window.time</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">long (default value <code class="literal">10000</code>)</code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>the length (in milliseconds) of the time-window (default 10 seconds)</p>
                              </td>
                           </tr>
                        </tbody>
                     </table>
                  </div>
               </div>
               <p>Example:</p>
               <p>The following call (with the default configuration):</p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.log.info('Hello %s', ['World'])</code></pre><p>produces the following output into the log:</p><pre class="programlisting highlight"><code data-lang="cypher">hello_world</code></pre></section>
         </section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>